<cfcomponent>

	<cffunction name="authorizeRequest" access="public" returntype="boolean">
		<!--- add comment to test svn --->
		<cfreturn true />
	</cffunction>
	
	<cffunction name="initResponseObj" access="public" output="false" returntype="struct">
		<cfset local.responseObj = StructNew() />
		<cfset responseObj.success = true />
		<cfset responseObj.message = "" />
		<cfset responseObj.data = "" />
		<cfset responseObj.recordcount = "" />
		<cfreturn responseObj />
	</cffunction>
	
	<cffunction name="logScholarOrientationCompleted" access="remote" output="false" returntype="any" returnformat="json">
		<cfargument name="Claim_ID" type="string" required="true" /> 
		<cfscript>
			var storedProcedureGateway = new assets.calgrants.com.gateway.StoredProcedureGateway();
		</cfscript>
		<cfreturn SerializeJSON(storedProcedureGateway.logScholarOrientationCompleted(argumentCollection = arguments)) />
	</cffunction>
	
	<cffunction name="getWorkshopsByCity" access="remote" output="false" returntype="any" returnformat="json">
		<cfargument name="city" type="string" required="true" /> 
		<cfscript>
			var workshopGateway = new assets.calgrants.com.gateway.WorkshopGateway();
			var base = new assets.calgrants.com.Base();
		</cfscript>
		<cfreturn SerializeJSON(base.QueryToStruct(workshopGateway.search(argumentCollection = arguments)), true) />
	</cffunction>

	<cffunction name="searchHighSchools" access="remote" output="false" returntype="any" returnformat="json">
		<cfargument name="searchString" type="string" required="true" /> 
		<cfscript>
			var storedProcedureGateway = new assets.calgrants.com.gateway.StoredProcedureGateway();
			var base = new assets.calgrants.com.Base();
		</cfscript>
		<cfreturn SerializeJSON(base.QueryToStruct(storedProcedureGateway.searchHighSchools(argumentCollection = arguments)), true) />
	</cffunction>
	
	<cffunction name="getWorkshopsByZipCode" access="remote" output="false" returntype="any" returnformat="json">
		<cfargument name="zipCode" type="string" required="true" /> 
		<cfscript>
			var workshopGateway = new assets.calgrants.com.gateway.WorkshopGateway();
			var base = new assets.calgrants.com.Base();
		</cfscript>
		<cfreturn SerializeJSON(base.QueryToStruct(workshopGateway.search(argumentCollection = arguments)), true) />
	</cffunction>

	<cffunction name="getWorkshopsByCounty" access="remote" output="false" returntype="any" returnformat="json">
		<cfargument name="county" type="string" required="true" /> 
		<cfscript>
			var workshopGateway = new assets.calgrants.com.gateway.WorkshopGateway();
			var base = new assets.calgrants.com.Base();
		</cfscript>
		<cfreturn SerializeJSON(base.QueryToStruct(workshopGateway.search(argumentCollection = arguments)), true) />
	</cffunction>
	
	<cffunction name="autocompleteCity" access="remote" output="false" returntype="any" returnformat="json">
		<cfargument name="term" type="string" required="true" /> 
		<cfscript>
			var storedProcedureGateway = new assets.calgrants.com.gateway.StoredProcedureGateway();
			var base = new assets.calgrants.com.Base();
		</cfscript>
		<cfreturn SerializeJSON(base.QueryToStruct(storedProcedureGateway.autocompleteCity(argumentCollection = arguments)), true) />
	</cffunction>
	
	<cffunction name="logMobileFacebookLike" access="remote" output="false" returntype="any" returnformat="json">
		<cfargument name="URL" type="string" required="true">
		<cfscript>
			var storedProcedureGateway = new assets.calgrants.com.gateway.StoredProcedureGateway();
		</cfscript>
		<cfreturn SerializeJSON(storedProcedureGateway.logMobileFacebookLike(argumentCollection = arguments)) />
	</cffunction>

	<cffunction name="query" access="remote" output="false" returntype="any" returnformat="json">
		<cfargument name="objType" type="string" required="yes">
		<cfset var isAuthorizedRequest = authorizeRequest() />
		<cfset var responseObj = initResponseObj() />
		<cfset var result = "" />
		<!--- <cfset var responseObj = initResponseObj() />
		<cfset var result = "" />
		<cfset var base = new assets.calgrants.com.Base() /> --->
		
		<cfif isAuthorizedRequest>
			<cftry>
				<cfinvoke component="assets.calgrants.com.gateway.#arguments.objType#Gateway" method="query" returnvariable="result">
					<cfinvokeargument name="argumentCollection" value="#arguments#" />
				</cfinvoke>
				
				<cfset responseObj["data"] = base.queryToStruct(result) />
				<cfset responseObj["recordcount"] = result.RecordCount />
				
				<cfcatch type="any">
					<cfset responseObj["success"] = false />
					<cfset responseObj["message"] = cfcatch />
				</cfcatch>
			</cftry>
			
		<cfelse>
			<cfset responseObj["success"] = false />
			<cfset responseObj["message"] = "Invalid request" />
		</cfif>	
		
		<cfreturn SerializeJSON(responseObj, true) />
	</cffunction>
	
	<cffunction name="save" access="remote" output="false" returntype="any" returnformat="json">
		<cfargument name="objType" type="string" required="yes">
		<cfset var isAuthorizedRequest = authorizeRequest() />
		<cfset var responseObj = initResponseObj() />
		<cfset var result = "" />
		
		<cfif isAuthorizedRequest>
		
			<cftry>
				<cfinvoke component="assets.calgrants.com.gateway.#arguments.objType#Gateway" method="save" returnvariable="result">
					<cfinvokeargument name="argumentCollection" value="#arguments#">
				</cfinvoke>
				
				<cfset responseObj["data"] = result />
			
				<cfcatch type="any">
					<cfset responseObj["success"] = false />
					<cfset responseObj["message"] = cfcatch />
				</cfcatch>
			</cftry>
			
		<cfelse>
			<cfset responseObj["success"] = false />
			<cfset responseObj["message"] = "Invalid request" />
		</cfif>	
		
		<cfreturn SerializeJSON(responseObj, true) />
	</cffunction>
	
	<cffunction name="create" access="remote" output="false" returntype="any" returnformat="json">
		<cfargument name="objType" type="string" required="yes">
		<cfset var isAuthorizedRequest = authorizeRequest() />
		<cfset var responseObj = initResponseObj() />
		<cfset var result = "" />
		
		<cfif isAuthorizedRequest>
		
			<cftry>
				<cfinvoke component="assets.calgrants.com.gateway.#arguments.objType#Gateway" method="save" returnvariable="result">
					<cfinvokeargument name="argumentCollection" value="#arguments#">
				</cfinvoke>
				
				<cfset responseObj["data"] = result />
			
				<cfcatch type="any">
					<cfset responseObj["success"] = false />
					<cfset responseObj["message"] = cfcatch />
				</cfcatch>
			</cftry>
			
		<cfelse>
			<cfset responseObj["success"] = false />
			<cfset responseObj["message"] = "Invalid request" />
		</cfif>	
		
		<cfreturn SerializeJSON(responseObj, true) />
	</cffunction>
	
	<!--- <cffunction name="read" access="remote" returntype="any" output="false" returnformat="json">
		<cfargument name="objType" type="string" required="yes">
		<cfset var isAuthorizedRequest = authorizeRequest() />
		<cfset var responseObj = initResponseObj() />
		<cfset var result = "" />
		<cfset var base = new assets.calgrants.com.Base() />
		
		<cfif isAuthorizedRequest>
			<cftry>
				<cfinvoke component="#application.pathToGateways#.#arguments.objType#Gateway" method="query" returnvariable="result">
					<cfinvokeargument name="argumentCollection" value="#arguments#" />
				</cfinvoke>
				
				<cfset responseObj["data"] = base.QueryToStruct(result) />
				<cfset responseObj["recordcount"] = result.RecordCount />
				
				<cfcatch type="any">
					<cfset responseObj["success"] = false />
					<cfset responseObj["message"] = cfcatch />
				</cfcatch>
			</cftry>
			
		<cfelse>
			<cfset responseObj["success"] = false />
			<cfset responseObj["message"] = "Invalid request" />
		</cfif>	
		
		<cfreturn SerializeJSON(responseObj, true) />
	</cffunction> --->
	
	<cffunction name="read" access="remote" output="false" returntype="any" returnformat="json">
		<cfargument name="objType" type="string" required="yes">
		<cfset var result = "" />
		<cfset var base = new assets.calgrants.com.Base() />
		<cftry>
			<cfif authorizeRequest()>
				<cfinvoke component="assets.calgrants.com.gateway.#arguments.objType#Gateway" method="query" returnvariable="result">
					<cfinvokeargument name="argumentCollection" value="#arguments#" />
				</cfinvoke>
			</cfif>
			<cfcatch type="any">
				<cfreturn SerializeJSON(cfcatch) />
			</cfcatch>
		</cftry>
		<cfreturn SerializeJSON(base.queryToStruct(result), true) />
	</cffunction>
	
	<cffunction name="update" access="remote" output="false" returntype="any" returnformat="json">
		<cfargument name="objType" type="string" required="yes">
		<cfset var isAuthorizedRequest = authorizeRequest() />
		<cfset var responseObj = initResponseObj() />
		<cfset var result = "" />
		
		<cfif isAuthorizedRequest>
		
			<cftry>
				<cfinvoke component="assets.calgrants.com.gateway.#arguments.objType#Gateway" method="save" returnvariable="result">
					<cfinvokeargument name="argumentCollection" value="#arguments#">
				</cfinvoke>
				
				<cfset responseObj["data"] = result />
			
				<cfcatch type="any">
					<cfset responseObj["success"] = false />
					<cfset responseObj["message"] = cfcatch />
				</cfcatch>
			</cftry>
			
		<cfelse>
			<cfset responseObj["success"] = false />
			<cfset responseObj["message"] = "Invalid request" />
		</cfif>	
		
		<cfreturn SerializeJSON(responseObj, true) />
		<!--- <cfargument name="objType" type="string" required="yes">
		<cfset var result = "" />
		<cftry>
			<cfif authorizeRequest()>
				<cfinvoke component="assets.calgrants.com.gateway.#arguments.objType#Gateway" method="save" returnvariable="result">
					<cfinvokeargument name="argumentCollection" value="#arguments#">
				</cfinvoke>
			</cfif>
			<cfif NOT IsInstanceOf(result, "assets.calgrants.com.bo.#arguments.objType#")>
				<cfset returnVal = result />
			<cfelse>
				<cfset returnVal = true />
			</cfif>
			<cfcatch type="any">
				<cfset returnVal = cfcatch />
			</cfcatch>
		</cftry>
		<cfreturn SerializeJSON(returnVal) /> --->
	</cffunction>
	
	<cffunction name="destroy" access="remote" output="false" returntype="any" returnformat="json">
		<cfargument name="objType" type="string" required="yes">
		<cfset var isAuthorizedRequest = authorizeRequest() />
		<cfset var responseObj = initResponseObj() />
		<cfset var result = "" />
		
		<cfif isAuthorizedRequest>
			
			<cftry>
				<cfinvoke component="assets.calgrants.com.gateway.#arguments.objType#Gateway" method="delete" returnvariable="result">
					<cfinvokeargument name="argumentCollection" value="#arguments#">
				</cfinvoke>
				
				<cfset responseObj["data"] = result />
				
				<cfcatch type="any">
					<cfset responseObj["success"] = false />
					<cfset responseObj["message"] = cfcatch />
				</cfcatch>
			</cftry>
			
		<cfelse>
			<cfset responseObj["success"] = false />
			<cfset responseObj["message"] = "Invalid request" />
		</cfif>	
		
		<cfreturn SerializeJSON(responseObj, true) />
	</cffunction>
	
	<cffunction name="chart" access="remote" output="false" returntype="any" returnformat="json">
		<cfset var isAuthorizedRequest = authorizeRequest() />
		<cfset var responseObj = initResponseObj() />
		<cfset var qObjs = "" />
		<cfset var base = new assets.calgrants.com.Base() />
		
		<cfif isAuthorizedRequest>
			<cftry>
				<cfinvoke component="ChartService" method="chart" returnvariable="qObjs">
					<cfinvokeargument name="argumentCollection" value="#arguments#" />
				</cfinvoke>
				
				<cfset responseObj["data"] = base.QueryToStruct(qObjs) />
				<cfset responseObj["recordcount"] = qObjs.RecordCount />
				
				<cfcatch type="any">
					<cfset responseObj["success"] = false />
					<cfset responseObj["message"] = cfcatch />
				</cfcatch>
			</cftry>
			
		<cfelse>
			<cfset responseObj["success"] = false />
			<cfset responseObj["message"] = "Invalid request" />
		</cfif>	
		
		<cfreturn SerializeJSON(responseObj, true) />
	</cffunction>
	
	<!--- <cffunction name="call" access="remote" output="false" returntype="any" returnformat="json">
		<cfargument name="service" type="string" required="yes">
		<cfset var isAuthorizedRequest = authorizeRequest() />
		<cfset var responseObj = initResponseObj() />
		<cfset var result = "" />
		<cfset var base = new assets.calgrants.com.Base() />
		
		<cfif isAuthorizedRequest>
			<cftry>
				<cfif arguments.service eq "procedure">
					<cfinvoke component="StoredProcedureService" method="call" returnvariable="result">
						<cfinvokeargument name="argumentCollection" value="#arguments#" />
					</cfinvoke>
				<cfelseif arguments.service eq "function">
					<cfinvoke component="FunctionService" method="#arguments.fx#" returnvariable="result">
						<cfinvokeargument name="argumentCollection" value="#arguments#" />
					</cfinvoke>
				</cfif>
				
				<cfif IsQuery(result)>
					<cfset responseObj["data"] = base.QueryToStruct(result) />
				<cfelse>
					<cfset responseObj["data"] = result />
				</cfif>
				
				<cfcatch type="any">
					<cfset responseObj["success"] = false />
					<cfset responseObj["message"] = cfcatch />
				</cfcatch>
			</cftry>
		<cfelse>
			<cfset responseObj["success"] = false />
			<cfset responseObj["message"] = "Invalid request" />
		</cfif>
		
		<cfreturn SerializeJSON(responseObj, true) />
	</cffunction> --->
	
	<cffunction name="generatePNG" access="remote" output="false" returntype="any" returnformat="json">
		<cfargument name="pngBase64String" type="string" required="yes" />
		<cfargument name="destination" type="string" required="yes" />
		<cfset var isAuthorizedRequest = authorizeRequest() />
		<cfset var responseObj = initResponseObj() />
		<cfset var base = new assets.calgrants.com.Base() />
		
		<cfif isAuthorizedRequest>
			<cftry>

				<cfset responseObj["data"] = base.generatePNG(argumentCollection = arguments) />
				
				<cfcatch type="any">
					<cfset responseObj["success"] = false />
					<cfset responseObj["message"] = cfcatch />
				</cfcatch>
			</cftry>
		<cfelse>
			<cfset responseObj["success"] = false />
			<cfset responseObj["message"] = "Invalid request" />
		</cfif>
		
		<cfreturn SerializeJSON(responseObj, true) />
	</cffunction>
	
	<!--- <cffunction name="saveFundWorkshopAppeal" access="remote" output="false" returntype="any" returnformat="json">
		<cfargument name="Fund_Workshop_Appeal_ID" type="numeric" required="yes" />
		<cfargument name="Deleted" type="boolean" required="no" default="0" />
		<cfargument name="Approved" type="boolean" required="no" default="0" />
		<cfargument name="Organization_ID" type="numeric" required="yes" />
		<cfargument name="Workshop_ID" type="numeric" required="yes" />
		<cfargument name="Appealed_By_ID" type="numeric" required="yes" />
		<cfargument name="Appeal" type="string" required="yes" />
		<cfargument name="Response" type="string" required="no" default="" />
		<cfset var isAuthorizedRequest = authorizeRequest() />
		<cfset var responseObj = initResponseObj() />
		<cfset var result = "" />
		
		<cfif isAuthorizedRequest>
		
			<cftry>
				<cfinvoke component="assets.calgrants.com.gateway.fundWorkshopAppealGateway" method="save" returnvariable="result">
					<cfinvokeargument name="argumentCollection" value="#arguments#">
				</cfinvoke>
				
				<cfset responseObj["data"] = result />
			
				<cfcatch type="any">
					<cfset responseObj["success"] = false />
					<cfset responseObj["message"] = cfcatch />
				</cfcatch>
			</cftry>
			
		<cfelse>
			<cfset responseObj["success"] = false />
			<cfset responseObj["message"] = "Invalid request" />
		</cfif>	
		
		<cfreturn SerializeJSON(responseObj, true) />
	</cffunction> --->
	
	<cffunction name="shareHowDidWeDoReport" access="remote" output="false" returntype="any" returnformat="json">
		<cfargument name="shareMessage" type="string" required="yes">
		<cfargument name="shareEmail" type="string" required="yes">
		<cfargument name="rollupLevel" type="string" required="yes">
		<cfargument name="ID" type="numeric" required="yes">
		<cfargument name="User_ID" type="numeric" required="yes">
		<cfargument name="Program_Year" type="string" required="yes" />
		<cfset var isAuthorizedRequest = authorizeRequest() />
		<cfset var responseObj = initResponseObj() />
		<cfset var base = new assets.calgrants.com.Base() />
		
		<cfif isAuthorizedRequest>
			<cftry>
				<cfset responseObj["data"] = base.shareHowDidWeDoReport(argumentCollection = arguments) />
				<cfcatch type="any">
					<cfset responseObj["success"] = false />
					<cfset responseObj["message"] = cfcatch />
				</cfcatch>
			</cftry>
		<cfelse>
			<cfset responseObj["success"] = false />
			<cfset responseObj["message"] = "Invalid request" />
		</cfif>
		
		<cfreturn SerializeJSON(responseObj, true) />
	</cffunction>
	
	<!--- <cffunction name="_checkStock" access="remote" output="false" returntype="any" returnformat="json">
		<cfargument name="productIDs" type="string" default="" />
		<cfargument name="Workshop_IDs" type="string" required="yes" />
		<cfargument name="Total_Anticipated_Students" type="numeric" required="yes" />
		<cfargument name="Unique_Volunteers" type="numeric" required="yes" />
		<cfscript>
			var base = new assets.calgrants.com.Base();
		</cfscript>
		<cfreturn SerializeJSON(base.getProductQuantityRules(argumentCollection = arguments), true) />
	</cffunction> --->
	
	<cffunction name="checkStock" access="remote" output="false" returntype="any" returnformat="json">
		<cfargument name="Product_ID" type="numeric" default="0" />
		<cfargument name="productIDs" type="string" default="" />
		<cfargument name="Workshop_IDs" type="string" required="yes" />
		<cfargument name="Total_Anticipated_Students" type="numeric" required="yes" />
		<cfargument name="Unique_Volunteers" type="numeric" required="yes" />
		<cfscript>
			var base = new assets.calgrants.com.Base();
		</cfscript>
		<cfreturn SerializeJSON(base.checkStock(argumentCollection = arguments), true) />
	</cffunction>
	
</cfcomponent>